package ar.com.cooker.services.uow.recipe;

import org.springframework.beans.factory.annotation.Autowired;

import ar.com.cooker.dao.RecipeDao;
import ar.com.cooker.model.Recipe;
import ar.com.cooker.services.pojo.RecipePojo;
import ar.com.cooker.services.uow.SaveAndUpdateUOW;
import ar.com.cooker.services.util.ConvertPojoToBO;

public class SaveAndUpdateRecipeOUW implements SaveAndUpdateUOW<RecipePojo>{

	@Autowired
	private RecipeDao recipeDao;
	
	@Override
	public void execute(RecipePojo u) {
		Recipe r = ConvertPojoToBO.getRecipeToRecipePojo(u);
		if(r.getId() == null){
			getRecipeDao().save(r);
		}else{
			getRecipeDao().update(r);
		}
		
	}

	public void setRecipeDao(RecipeDao recipeDao) {
		this.recipeDao = recipeDao;
	}

	public RecipeDao getRecipeDao() {
		return recipeDao;
	}

}
